unit FMenuDefault;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Db, Buttons, DBClient, Variants, ADODB;

type
  TF_MenuDefault = class(TForm)
    lbAll: TListBox;
    Label1: TLabel;
    btnS: TBitBtn;
    btnC: TBitBtn;
    procedure FormShow(Sender: TObject);
  private
    fOld: string;
  public
    function ModalShow(sOld: string; var sDefault: string): Integer;
  end;

var
  F_MenuDefault: TF_MenuDefault;

implementation

//uses uMain;
uses uDbAccess, uGlobalFunc;
{$R *.DFM}

function TF_MenuDefault.ModalShow(sOld: string; var sDefault: string): Integer;
var
  s: string;
begin
  fOld := sOld;
  Result := ShowModal;
  if result = mrOK then
  begin
    s := lbAll.Items[lbAll.ItemIndex];
    if lbAll.ItemIndex > -1 then
      sDefault := Copy(s, 2, Pos(')', s) - 2)
    else
      sDefault := '';
  end;
end;

procedure TF_MenuDefault.FormShow(Sender: TObject);
var
  sError: string;
  vOutput: OleVariant;
  sql: string;
  cds: TClientDataSet;
begin

  sql := 'select menuset_id,menuset_name from sm_opmenuset where menuset_id<>'''
    + fOld + ''' order by menuset_id';
  if not GetData(sql, false, vOutput) then
  begin
    MsgDlg(vOutput, mtError);
    exit;
  end;
  cds := TClientDataSet.Create(nil);
  cds.Data := vOutput;
  while not cds.eof do
  begin
    lbAll.Items.add('(' + Trim(cds.Fields[0].asString) + ')' +
      Trim(cds.Fields[1].asString));
    cds.Next;
  end;
  cds.Free;
  if lbAll.Count > 0 then
    lbAll.Selected[0] := true;
end;

end.

